// copyright jyz.2024

#pragma once

#include "CoreMinimal.h"
#include "GameplayTagContainer.h"
#include "GameFramework/PlayerController.h"
#include "AuraPlayerController.generated.h"

class UDamageTextComponent;
class USplineComponent;
struct FInputActionValue;
class UInputMappingContext;
class UInputAction;
class IEnemyInterface;
class UAuraInputConfig;
class UAuraAbilitySystemComponent;
/**
 */
UCLASS()
class AURARPGDEMO_API AAuraPlayerController : public APlayerController
{
	GENERATED_BODY()
public:
	AAuraPlayerController();

	UFUNCTION(Client,Reliable)
	void ShowDamageNumber(float DamageAmount,ACharacter* TargetCharacter);
protected:
	virtual void BeginPlay() override;
	virtual void PlayerTick(float DeltaTime) override;
	virtual void SetupInputComponent() override;
private:
	UPROPERTY(EditAnywhere,Category=Input)
	TObjectPtr<UInputAction> IA_MoveAction;
	UPROPERTY(EditAnywhere,Category=Input)
	TObjectPtr<UInputAction> IA_ShiftAction;
	UPROPERTY(EditAnywhere,Category=Input)
	TObjectPtr<UInputMappingContext> IMC_AuraContext;
	UPROPERTY(EditDefaultsOnly,Category=Input)
	TObjectPtr<UAuraInputConfig> InputConfig;
	void OnMove(const FInputActionValue&InValue);
	void OnShiftPressed(const FInputActionValue&InValue);
	void OnShiftReleased(const FInputActionValue&InValue);
	bool bShiftKeyDown = false;
	void OnInputTagPressed(FGameplayTag InputTag);
	void OnInputTagReleased(FGameplayTag InputTag);
	void OnInputTagHeld(FGameplayTag InputTag);
	void CursorTrace();

	void MoveToCursorFromShortPressed();
	IEnemyInterface* LastActor;
	IEnemyInterface* ThisActor;
	//鼠标每帧的碰撞结果
	FHitResult CursorHit;
	
	UPROPERTY()
	TObjectPtr<UAuraAbilitySystemComponent> AuraASC;

	UAuraAbilitySystemComponent* GetASC();
	void AutoRun();

private:
	FVector CacheDestination;
	float FollowTime = 0.f;
	float ShortPressThreshold = 0.5f;
	bool bAutoRunning = false;
	bool bTargeting = false;
	UPROPERTY(EditDefaultsOnly)
	float AutoRunAcceptanceRadius = 50.f;
	UPROPERTY(VisibleAnywhere)
	TObjectPtr<USplineComponent> SplineComponent;

	UPROPERTY(EditDefaultsOnly)
	TSubclassOf<UDamageTextComponent> DamageTextComponentClass;
};
